package util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Calendar;
import java.util.GregorianCalendar;

import entity.Event;
import entity.ICalendar;

public class Driver {
	public static void main(String[] args) {
		String fileName = "TestCal";
		
		//Create ICalendar with default timezone and set version
		ICalendar cal = new ICalendar("iCalTest");
		cal.setVersion("2.0");
		
		//Set start and end date
		GregorianCalendar startDate = new GregorianCalendar(2014, Calendar.AUGUST, 13, 20, 0); //UTC TIME
		GregorianCalendar endDate = new GregorianCalendar(2014, Calendar.AUGUST, 13, 23, 0);   //UTC TIME
		
		//Create event and add properties
		Event event = new Event();
		event.addSummary("Study for Exam - Hamilton Library");
		event.addDateTimeStart(startDate.getTime());
		event.addDateTimeEnd(endDate.getTime());
		
		//Add event to calendar
		cal.addEvent(event);
		
		//Write ICalendar to file and print to console
		String file = fileName + ".ics";
		File icsFile = new File(file);
		try{
			Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(icsFile), "UTF-8"));
			out.write(cal.toString());
			out.close();
			System.out.print(cal.toString());
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}
